package com.juku2024.juku.adapter

import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.model.CommonModel
import com.juku2024.juku.tools.AppUtils
import com.juku2024.juku.tools.ImageUtils
import java.util.*

class CategoryListAdapter(data: ArrayList<CommonModel>) :
    BaseQuickAdapter<CommonModel, BaseViewHolder>(R.layout.item_home_tab_grid2, data), LoadMoreModule {

    var isMovie = false

    override fun convert(holder: BaseViewHolder, item: CommonModel) {
        val iv = holder.getView<ImageView>(R.id.iv_home)
        ImageUtils.loadImageV(iv, item.pic)

        val ivShortPlays = holder.getView<ImageView>(R.id.iv_short_plays)
        val visibility = if (item.sp) {
            View.VISIBLE
        } else {
            View.GONE
        }
        ivShortPlays.visibility = visibility

        val colorId = if (isMovie)
            R.color.cFF6D2F
        else
            R.color.cFFFFFF
        val tag = if (isMovie) {
            item.score
        } else {
            item.update_progress
        }
        holder.setText(R.id.tv_update, tag)
            .setText(R.id.tv_title, item.name)
            .setTextColor(R.id.tv_update, AppUtils.getColor(colorId))

        if (!item.isWatching) return
        val newEpisode= item.theLastEpisode?:0
        holder.setGone(R.id.ic_new, newEpisode <= 0)
    }

}